Animated Rendering for Progress Bars, Loaders, and More #188
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces animated rendering capabilities to Termwind, allowing for dynamic updates of CLI components like progress bars or any other live-rendered element. I've developed this feature to use in my own package (see: https://github.com/pdphilip/elasticlens) and would love to contribute it back to Termwind.
Why:
Termwind offers excellent flexibility in designing CLI interfaces, but the standard progress bars often look out of place. This PR enhances Termwind's potential by enabling real-time updates to rendered elements, leveraging all its existing design capabilities. This is useful for progress bars, loaders, or any component that requires continuous updates.
Real-world example:
2 New Functions:
1.
liveRender(string $html = '', int $options): LiveHtmlRenderer
reRender()
is calledExample: Progress Bar
A More Practical Example:
Demo*
2.
asyncFunction(callable $task): AsyncHtmlRenderer
pcntl_fork()
is unavailable, it falls back to synchronous behaviour. ierender -> task -> render
Note:
$result
will betrue
$result
will befalse
Usage:
Demo
Addendum
Below are the blade files used in the demo examples:
Progress Bar: Example 1
Progress Bar: Example 2
Progress Bar: Example 3
Loader: Example 1
Loader: Example 2
Loader: Example 3
(This one is insanely complicated, but just showing what’s possible)